#define _CRT_SECURE_NO_WARNINGS 1
#include "Queue.h"
void QueueInit(Queue* pq)
{
	assert(pq);
	pq->phead = pq->ptail = NULL;
	pq->size = 0;
}
void QueueDestroy(Queue* pq)
{
	assert(pq);
	QueueNode* tmp = pq->phead;
	while (tmp)
	{
		Queue* next = tmp->next;
		free(tmp);
		tmp = next;
	}
	pq->phead = pq->ptail = NULL;
	pq->size = 0;
}
void QueuePush(Queue* pq, QDateType value)
{
	assert(pq);
	QueueNode* newnode = (QueueNode*)malloc(sizeof(QueueNode));
	if (newnode == NULL)
	{
		perror("malloc error!");
		exit(1);
	}
	newnode->value = value;
	newnode->next = NULL;
	if (pq->phead == NULL)
	{
		pq->phead = pq->ptail = newnode;
	}
	else
	{
		pq->ptail->next = newnode;
		pq->ptail = newnode;
	}
	pq->size++;
}
void QueuePop(Queue* pq)
{
	assert(pq && pq->size);
	QueueNode* del = pq->phead;
	pq->phead = pq->phead->next;
	if (pq->phead == NULL)
		pq->ptail = NULL;
	free(del);
	del = NULL;
	--pq->size;
}
QDateType QueueBack(Queue* pq)
{
	assert(pq && pq->size);
	return pq->ptail->value;
}
QDateType QueueFront(Queue* pq)
{
	assert(pq && pq->size);
	return pq->phead->value;
}
bool QueueEmpty(Queue* pq)
{
	assert(pq);
	return !pq->size;
}
int QueueSize(Queue* pq)
{
	assert(pq);
	return pq->size;
}